package org.example.exts;

import java.io.IOException;
import java.util.EventListener;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.component.LifeCycle;
import org.omg.PortableServer.LifespanPolicyValue;

public class MyHandler implements Handler
{
	
	private String printStr ;
	
	public MyHandler( String printStr) {
		this.printStr = printStr ;
	}
	
	@Override
	public void stop() throws Exception {
		System.err.println("stop method") ;
	}
	
	@Override
	public void start() throws Exception {
		System.err.println("start method") ;
	}
	
	@Override
	public void removeLifeCycleListener(Listener listener) {
		System.err.println("removeLifeCycleListener method") ;				
	}
	
	@Override
	public boolean isStopping() {
		System.err.println("isStopping method is false") ;
		return false;
	}
	
	@Override
	public boolean isStopped() {
		System.err.println("isStopped method is true") ;
		return true;
	}
	
	@Override
	public boolean isStarting() {
		System.err.println("isStarting method is false") ;
		return false;
	}
	
	@Override
	public boolean isStarted() {
		System.err.println("isStarted method is true") ;
		return true;
	}
	
	@Override
	public boolean isRunning() {
		System.err.println("isRunning method is false") ;
		return false;
	}
	
	@Override
	public boolean isFailed() {
		System.err.println("isRunning method is false") ;
		return false;
	}
	
	@Override
	public void addLifeCycleListener(Listener listener) {
		System.err.println("addLifeCycleListener method") ;
	}
	
	@Override
	public void setServer(Server server) {
		System.err.println("setServer method") ;
	}
	
	@Override
	public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		System.err.println("handle method print is "+ this.printStr) ;
		baseRequest.setHandled(false);
	}
	
	@Override
	public Server getServer() {
		System.err.println("handle method") ;
		return null;
	}
	
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}
	
	
	public class MyListener implements LifeCycle.Listener
    {

		@Override
		public void lifeCycleStarting(LifeCycle event) {
			
		}

		@Override
		public void lifeCycleStarted(LifeCycle event) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void lifeCycleFailure(LifeCycle event, Throwable cause) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void lifeCycleStopping(LifeCycle event) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void lifeCycleStopped(LifeCycle event) {
			// TODO Auto-generated method stub
			
		}
      
    }
}
